package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.domain.clue.CluePoolDO;
import com.qk.dto.clue.*;
import com.qk.entity.Clue;
import com.qk.management.service.ClueService;
import com.qk.common.Result;
import com.qk.vo.clue.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


@Slf4j
@RestController
@RequestMapping("/clues")
public class ClueController {

    @Autowired
    private ClueService clueService;
    @GetMapping("/pool")
    public Result pool(CluePoolDTO cluePoolDTO) {
        PageResult<CluePoolDO> list = clueService.selectPool(cluePoolDTO);
        return Result.success(list);
    }

    @PutMapping("/false/{id}")
    public Result toFalse(@PathVariable Integer id, @RequestBody MarkFalseClueDto dto) {
        clueService.toFalse(id, dto);
        return Result.success();
    }
    @PutMapping("/toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }
    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto) {
        clueService.updateClueInfoById(dto);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getClueById(@PathVariable Integer id) {
        log.info("通过id查询:{}",id);
        ClueVO clueVO = clueService.getClueById(id);
        return Result.success(clueVO);
    }

    @PutMapping("/assign/{clueId}/{userId}")
    public Result update(@PathVariable Integer clueId, @PathVariable Integer userId){
        clueService.updateById(Clue.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.STATUS_WAIT_FOLLOW)
                .build());
        return Result.success();
    }
    @GetMapping
    public Result selectByPage(ClueListDTO clueListDTO){
        PageResult<ClueDO> clues = clueService.selectByPage(clueListDTO);
        return Result.success(clues);
    }

    @PostMapping
    public Result addClue(@RequestBody ClueDTO clueDTO) {
        clueService.addClue(clueDTO);
        return Result.success();
    }

}